/*
 * @Description:
 * @Author: Rfan
 * @Date: 2022-02-16 13:22:51
 * @LastEditTime: 2022-02-16 15:13:17
 */
import Mock from 'mockjs';

const List = [];
for (let i = 0; i < 20; i++) {
  List.push(
    Mock.mock({
      id: '@increment',
      atCode: '@increment(100)',
      atName: `@ctitle(2)档案`,
      atLevel: '@integer(1, 3)',
      operateTime: +Mock.Random.date('T'),
      operator: '@cname',
      remark: 'cparagraph()'
    })
  );
}

export default [
  {
    url: '/sys-arctypeinfo/list/fonds-id/',
    type: 'get',
    response: (config) => {
      const { importance, type, title, sort } = config.query;
      const id = /\/sys-arctypeinfo\/list\/fonds-id\/(\d+)/.exec(config.url)[1];

      let mockList = List.filter((item) => {
        if (importance && item.importance !== +importance) return false;
        if (type && item.type !== type) return false;
        if (title && item.title.indexOf(title) < 0) return false;
        return true;
      });

      if (sort === '-id') {
        mockList = mockList.reverse();
      }

      const pageList = mockList
        .filter((item, index) => index < 8)
        .map((item) => {
          item.fondId = parseInt(id, 10);
          return item;
        });

      return {
        code: 200,
        data: pageList
      };
    }
  },
  {
    url: '/sys-arctypeinfo/level/',
    type: 'get',
    response: (config) => {
      const id = /\/sys-arctypeinfo\/level\/(\d+)/.exec(config.url)[1];
      const _list = [];
      for (let i = 0; i < 4; i++) {
        _list.push(
          Mock.mock({
            level: i,
            levelName: `@ctitle(2)级`
          })
        );
      }
      const mockList = _list.reverse().map((item) => {
        item.archiveTypeId = id;
        return item;
      });

      return {
        code: 200,
        data: mockList,
        massage: 'success'
      };
    }
  }
];
